/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package net.alteiar.behaviours.basic;

import jade.domain.FIPAAgentManagement.FailureException;
import jade.domain.FIPAAgentManagement.NotUnderstoodException;
import jade.domain.FIPAAgentManagement.RefuseException;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.proto.SimpleAchieveREResponder;
import net.alteiar.agent.GamePlayerAgent;

/**
 * @author Cody Stoutenburg
 * 
 */
public abstract class GameSimpleCommunicationResponder extends
		SimpleAchieveREResponder {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/*
	 * This protocol work in that way: 
	 * - send message (constructor) 
	 * - wait for reply 
	 * 		- not-understood 
	 * 		- refuse 
	 * 		- agree
	 * 		
	 */
	/**
	 * @param a
	 * @param msg
	 */
	public GameSimpleCommunicationResponder(GamePlayerAgent a,
			MessageTemplate template) {
		super(a, template);
	}

	protected GamePlayerAgent getMyAgent() {
		return (GamePlayerAgent) myAgent;
	}

	/**
	 * This method is called when the initiator's message is received that
	 * matches the message template passed in the constructor. This default
	 * implementation return null which has the effect of sending no reponse.
	 * Programmers should override the method in case they need to react to this
	 * event.
	 * 
	 * @param request
	 *            the received message
	 * @return the ACLMessage to be sent as a response (i.e. one of
	 *         <code>agree, refuse, not-understood, inform</code>. <b>Remind</b>
	 *         to use the method createReply of the class ACLMessage in order to
	 *         create a good reply message
	 * @see jade.lang.acl.ACLMessage#createReply()
	 **/
	@Override
	protected abstract ACLMessage prepareResponse(ACLMessage request)
			throws NotUnderstoodException, RefuseException;

	/**
	 * This method is called after the response has been sent and only when one
	 * of the folliwing two cases arise: the response was an <code>agree</code>
	 * message OR no response message was sent. This default implementation
	 * return null which has the effect of sending no result notification.
	 * Programmers should override the method in case they need to react to this
	 * event.
	 * 
	 * @param request
	 *            the received message
	 * @param response
	 *            the previously sent response message
	 * @return the ACLMessage to be sent as a result notification (i.e. one of
	 *         <code>inform, failure</code>. <b>Remind</b> to use the method
	 *         createReply of the class ACLMessage in order to create a good
	 *         reply message
	 * @see jade.lang.acl.ACLMessage#createReply()
	 * @see #prepareResponse(ACLMessage)
	 **/
	@Override
	protected abstract ACLMessage prepareResultNotification(ACLMessage request,
			ACLMessage response) throws FailureException;
}
